<?php

/**
 * 控制台
 *
 * @package		Hooloo framework
 * @author 		Bill
 * @copyright 	Hooloo Co.,Ltd
 * @version		1.0
 * @release		2017.05.08
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class Market extends Controller{
    public function __construct(){
        parent::__construct();
    }
    /*
         * market 实时行情接口函数
         * 可通过get或post方式访问返回json格式数据
         * @code 必传参数 股票代码 如果查询上证指数需要用sh000001
         */
    public function market()
    {
        $data = getParam();
        $code = $data['code'];
        $uid = MID;
        if ($code === null) {
            ajax_return(0,'请搜索股票',null);
        }
        $data = z_market($code);
        if (!$data) {
            ajax_return(0,'操作失败',$data);
        }
        $sub = Db::name('stock_subaccount_self')
            ->where('uid='.$uid)
            ->where('gupiao_code='.$code)
            ->find();
        if (!empty($sub)){
            $data['sub'] = 1;
        }else{
            $data['sub'] = 0;
        }
        $p_range = $data['currency'] - $data['yesterday_price'];
        $data['price_range'] = round($p_range,2);
        $data['price_rate'] = round(($p_range/$data['yesterday_price']*100),2);
        ajax_return(1,'操作成功',$data);
//        return json(['data' => $data, 'status' => 1, 'code' => 1,'message' => '操作成功']);

    }
}